﻿<UserControl x:Class="ScrumFactory.Team.MembersList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"     
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"
             
             x:Name="thisView"
             
             
             mc:Ignorable="d"                   
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding RefreshCommand}" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <DataTemplate x:Key="MemberDataTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <ContentControl                        
                        DataContext="{Binding MemberProfile}"
                        Grid.Column="0"
                        Margin="0,3,20,3"
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        Style="{StaticResource MemberImageControlStyle}"/>
                <StackPanel Grid.Column="1">
                    <TextBlock TextTrimming="CharacterEllipsis">
                        <Hyperlink 
                            Command="{Binding Model.ShowDetailWindowCommand, ElementName=thisView}"
                            CommandParameter="{Binding .}">
                            <Run Text="{Binding MemberProfile.FullName}" FontSize="{StaticResource BigFontSize}"  />        
                        </Hyperlink>
                    </TextBlock>
                    
                        
                    <TextBlock Text="{Binding MemberProfile.CompanyName}" Foreground="{StaticResource AlertBrush}" FontSize="{StaticResource NormalFontSize}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis">
                        <TextBlock.Style>
                            <Style>
                                <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsContactMember}" Value="True">
                                        <Setter Property="TextBlock.Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <TextBlock>                                
                                    <Hyperlink                                           
                                            SF_Comp:CommandBehavior.RoutedEventName="Click"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding SendEmailCommand}">
                                        <Run Text="{Binding MemberProfile.EmailAccount}" FontSize="{StaticResource SmallFontSize}" />    
                                    </Hyperlink>                                    
                 </TextBlock>
                    <TextBlock Text="{Binding MemberProfile.Skills}" Foreground="{StaticResource SubTextBrush}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </StackPanel>
                <Path                  
                    Grid.Column="2"
                    StrokeLineJoin="Round" SnapsToDevicePixels="True"
                    DataContext="{Binding MemberProfile.DayOccupation}"
                    Style="{StaticResource DayAllocationPath}"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>           
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

      
        <TextBox 
            Grid.Row="0" Grid.ColumnSpan="2"
            HorizontalAlignment="Stretch" Margin="3,3,15,3"
            Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}"
            Style="{StaticResource SearchTextBox}"
            ToolTip="{x:Static props:Resources.Name_or_qualification}" />

        <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Margin="5">
            <TextBlock 
             VerticalAlignment="Center" 
            Style="{StaticResource LabelTextBlock}" Text="{x:Static props:Resources.Member_work_load}"/>

            <ComboBox                                                                                                                       
            VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3,0,0,0"
            SelectedValue="{Binding SearchMemberAvailability}"                                
            Style="{StaticResource MemberAvailabilityComboBox}"/>
        </StackPanel>
        
            
        
        <CheckBox
            Grid.Row="1" Grid.Column="1" Margin="5"
            IsChecked="{Binding OnlyActiveMembers}" HorizontalAlignment="Right"
            Content="{x:Static props:Resources.only_active}"/>
        
        <TextBlock 
            Grid.Row="2" Grid.ColumnSpan="2" Margin="5,5,5,5"
            Text="{Binding Items.Count, ElementName=membersListBox, StringFormat={x:Static props:Resources.n_people_were_found}}" />

        <ListBox    
            x:Name="membersListBox"
            Grid.Row="3" Grid.ColumnSpan="2"            
            ItemContainerStyle="{StaticResource HorizontalLineDividedNoSelectionListBoxItem}"
            SF_Helpers:ItemActivation.ActivationMode="Both"            
            SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowDetailWindowCommand}"                                    
                    
            VirtualizingStackPanel.IsVirtualizing="True" 
            ScrollViewer.IsDeferredScrollingEnabled="True"
            ItemsSource="{Binding FilteredMembers}" SelectionMode="Single"
            
            Background="Transparent"
            BorderThickness="0"
            HorizontalContentAlignment="Stretch"                                        
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            ItemTemplate="{StaticResource MemberDataTemplate}">

          
     
        </ListBox>

        <ContentControl Grid.Row="2" Grid.ColumnSpan="2"
                        Style="{StaticResource LoadingAnimationContent}"/>

        <Grid
            Grid.Row="2" Grid.ColumnSpan="2"
            MaxWidth="300" Margin="0,20,0,0"
            HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="/Images/information.png"  Width="16" Height="16" Stretch="Uniform" Margin="3" VerticalAlignment="Top" />
            <TextBlock Grid.Column="1" TextWrapping="Wrap" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static props:Resources.No_members_were_found}"/><LineBreak/>
                <TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.No_members_were_found_tooltip}"/>
            </TextBlock>
            <Grid.Style>
                <Style>
                    <Setter Property="Grid.Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=membersListBox, Path=HasItems}" Value="False"/>
                                <Condition Binding="{Binding IsLoadingData}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Grid.Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
        </Grid>


    </Grid>
</UserControl>
